<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      table,
      td {
        border: 1px solid yellow;
        border-spacing: 0;
        border-collapse: collapse;
        margin: auto;
      }
    </style>
  </head>
  <body>
    <script>
      var str = "";
      var box = "";
      var arr = [
        {
          name: "Jack",
          age: 18,
          gender: "男",
        },
        {
          name: "Rose",
          age: 20,
          gender: "女",
        },
        {
          name: "Top",
          age: 22,
          gender: "男",
        },
      ];
      function fn() {
        document.write("<table>");
        for (var i = 0; i < arr.length; i++) {
          document.write("<tr>");
          for (var key in arr[i]) {
            document.write("<td>");
            document.write(arr[i][key]);
            document.write("</td>");
          }
          document.write("</tr>");
        }
        document.write("</table>");
      }
      fn();
    </script>
  </body>
</html>
